package ewms.controller;

import java.util.List;
import java.util.Arrays;

import ewms.bo.EwmsEntryWarehouseAddBo;
import ewms.service.IEwmsEntryWarehouseService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import ewms.common.annotation.RepeatSubmit;
import ewms.common.annotation.Log;
import ewms.common.core.controller.BaseController;
import ewms.common.core.domain.AjaxResult;
import ewms.common.enums.BusinessType;
import ewms.vo.EwmsEntryWarehouseVo;
import ewms.bo.EwmsEntryWarehouseQueryBo;
import ewms.bo.EwmsEntryWarehouseEditBo;
import ewms.common.utils.poi.ExcelUtil;
import ewms.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 危废入库Controller
 *
 * @author zhaoxiaochun
 * @date 2022-02-09
 */
@Api(value = "危废入库控制器", tags = {"危废入库管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/entryWarehouse")
public class EwmsEntryWarehouseController extends BaseController {

    private final IEwmsEntryWarehouseService iEwmsEntryWarehouseService;

	/**
	 * 查询危废待入库列表
	 */
	@ApiOperation("查询危废待入库列表")
	@PreAuthorize("@ss.hasPermi('business:entryWarehouse:list')")
	@GetMapping("/preEntryList")
	public TableDataInfo<EwmsEntryWarehouseVo> preEntryList(@Validated EwmsEntryWarehouseQueryBo bo) {
		return iEwmsEntryWarehouseService.selectPagePreEntryWarehouseList(bo);
	}

	/**
	 * 导出危废待入库列表
	 */
	@ApiOperation("导出危废入库列表")
	@PreAuthorize("@ss.hasPermi('business:entryWarehouse:export')")
	@Log(title = "危废入库", businessType = BusinessType.EXPORT)
	@GetMapping("/preEntryExport")
	public AjaxResult<EwmsEntryWarehouseVo> preEntryExport(@Validated EwmsEntryWarehouseQueryBo bo) {
		List<EwmsEntryWarehouseVo> list = iEwmsEntryWarehouseService.selectPreEntryWarehouseList(bo);
		ExcelUtil<EwmsEntryWarehouseVo> util = new ExcelUtil<EwmsEntryWarehouseVo>(EwmsEntryWarehouseVo.class);
		return util.exportExcel(list, "危废入库");
	}

    /**
     * 查询危废入库列表
     */
    @ApiOperation("查询危废入库列表")
    @PreAuthorize("@ss.hasPermi('business:entryWarehouse:list')")
    @GetMapping("/list")
    public TableDataInfo<EwmsEntryWarehouseVo> list(@Validated EwmsEntryWarehouseQueryBo bo) {
        return iEwmsEntryWarehouseService.selectPageEntryWarehouseList(bo);
    }

    /**
     * 导出危废入库列表
     */
    @ApiOperation("导出危废入库列表")
    @PreAuthorize("@ss.hasPermi('business:entryWarehouse:export')")
    @Log(title = "危废入库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EwmsEntryWarehouseVo> export(@Validated EwmsEntryWarehouseQueryBo bo) {
        List<EwmsEntryWarehouseVo> list = iEwmsEntryWarehouseService.selectEntryWarehouseList(bo);
        ExcelUtil<EwmsEntryWarehouseVo> util = new ExcelUtil<EwmsEntryWarehouseVo>(EwmsEntryWarehouseVo.class);
        return util.exportExcel(list, "危废入库记录");
    }

    /**
     * 获取危废入库详细信息
     */
    @ApiOperation("获取危废入库详细信息")
    @PreAuthorize("@ss.hasPermi('business:entryWarehouse:query')")
    @GetMapping("/{entryWarehouseId}")
    public AjaxResult<EwmsEntryWarehouseVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("entryWarehouseId") Long entryWarehouseId) {
        return AjaxResult.success(iEwmsEntryWarehouseService.queryById(entryWarehouseId));
    }

    /**
     * 新增危废入库
     */
    @ApiOperation("新增危废入库")
    @PreAuthorize("@ss.hasPermi('business:entryWarehouse:add')")
    @Log(title = "危废入库", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody EwmsEntryWarehouseAddBo bo) {
        return toAjax(iEwmsEntryWarehouseService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改危废入库
     */
    @ApiOperation("修改危废入库")
    @PreAuthorize("@ss.hasPermi('business:entryWarehouse:edit')")
    @Log(title = "危废入库", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody EwmsEntryWarehouseEditBo bo) {
        return toAjax(iEwmsEntryWarehouseService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除危废入库
     */
    @ApiOperation("删除危废入库")
    @PreAuthorize("@ss.hasPermi('business:entryWarehouse:remove')")
    @Log(title = "危废入库" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{entryWarehouseIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] entryWarehouseIds) {
        return toAjax(iEwmsEntryWarehouseService.deleteWithValidByIds(Arrays.asList(entryWarehouseIds), true) ? 1 : 0);
    }
}
